package com.hgy.commonsale.webui.action.product;

import java.util.List;

import org.geln.web.status.Status;

import util.CommonUtil;

import com.hgy.commonsale.product.GoodKinds;
import com.hgy.commonsale.service.GoodKindManagerService;
import com.hgy.commonsale.webui.action.AnonymousAction;


public class GoodKindsAction extends AnonymousAction {

	private String kindName;
	private String kindDesc;
	private GoodKindManagerService goodKindManagerService;
	private List<GoodKinds> lstGoodKinds;

	public GoodKindManagerService getGoodKindManagerService() {
		return goodKindManagerService;
	}

	public void setGoodKindManagerService(
			GoodKindManagerService goodKindManagerService) {
		this.goodKindManagerService = goodKindManagerService;
	}

	public List<GoodKinds> getLstGoodKinds() {
		return lstGoodKinds;
	}

	public void setLstGoodKinds(List<GoodKinds> lstGoodKinds) {
		this.lstGoodKinds = lstGoodKinds;
	}

	public String getKindName() {
		return kindName;
	}

	public void setKindName(String kindName) {
		this.kindName = kindName;
	}

	public String getKindDesc() {
		return kindDesc;
	}

	public void setKindDesc(String kindDesc) {
		this.kindDesc = kindDesc;
	}

	public String execute() {

		if(CommonUtil.isEmpty(kindName)||CommonUtil.isEmpty(kindDesc)){
			return INPUT;
		}
		GoodKinds goodKinds = new GoodKinds();
		goodKinds.setGoodKindName(kindName);
		goodKinds.setGoodKindCode(kindName);
		goodKinds.setGoodKindDescriptionEn(kindDesc);
		goodKinds.setIsActive("true");
		
		if (CommonUtil.isEmpty(goodKindManagerService.saveObject(goodKinds))) {
			addActionError(getText("error.message.GoodNameRepeated"));
			return INPUT;

		} else {
			addActionMessage(getText("success.add.over"));
			return INPUT;
		}

	}

	public String doGetAllKindsList() {
		lstGoodKinds = goodKindManagerService.getKindsList();
		if (lstGoodKinds.size() <= 0) {
			addActionError(getText("error.message.notHaveKind"));
			return INPUT;
		}

		return SUCCESS;
	}

	
	public String doDeleteOneKind() {
		
		Status status=goodKindManagerService.deleteObjectByName(kindName);
		if(Status.SUCCESS.equals(status)){
			return SUCCESS;
		}else if(Status.FAILED.equals(status)){
			return ERROR;
		}
		
		return INPUT;
	}

}
